<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增公告')" />
	<th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-manager-add">
        <div class="form-group">
            <label class="col-sm-2 control-label">公告主题：</label>
            <div class="col-sm-10">
                <input id="title" name="title" class="form-control" type="text" required placeholder="请输入公告主题">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">有效期：</label>
            <div class="col-sm-10">
                <div class="input-daterange input-group">
                    <input type="text" class="time-input form-control" id="timeStart" name="time_start"
                           placeholder="开始时间" readonly>
                    <span class="input-group-addon">-</span>
                    <input type="text" class="time-input form-control" id="timeEnd" name="time_end" placeholder="结束时间"
                           readonly>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">公告内容：</label>
            <div class="col-sm-10">
                <input id="content" name="content" class="form-control" type="text" required placeholder="请输入公告内容">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">公告类型：</label>
            <div class="col-sm-10">
                <select name="parent_id" lay-search="" class="form-control input1" data-placeholder="请选择">
                    <!--<option value="">请选择</option>-->
                    <option th:selected="${type.tid eq type.tid}" th:each="type : ${types}"
                            th:value="${type.tid}" th:text="${type.tname}">
                    </option>
                </select>
            </div>
        </div>

    </form>
</div>
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: select2-js" />
	<script>
	    var prefix = ctx + "notice/manager";

		$(function() {
            $('#post').select2({
                placeholder: "请选择公告类别",
                allowClear: true
            });
        })

        $("#form-manager-add").validate({
            onkeyup: false,
            rules:{
                title:{
                    remote: {
                        url: ctx + "notice/manager/checkManagerNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "title" : function() {
                                return $.common.trim($("#title").val());
                            }
                        },
                        dataFilter: function(data, type) {
                            return $.validate.unique(data);
                        }
                    }
                },
                postSort:{
                    digits:true
                },
            },
            messages: {
                "title": {
                    remote: "公告名称已经存在"
                }
            },
            focusCleanup: true
        });

        function submitHandler() {
            var serialize = $('#form-manager-add').serialize();
            console.info(serialize)
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-manager-add').serialize());
            }
        }

    </script>
</body>
</html>